package com.kitkat.entities;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

import com.kitkat.util.MyUtil;

@NamedQueries({
	@NamedQuery(name="getProjectsByUserid",query="from Project p where p.user.id=:userid")
})

@Entity
@Table(name="t_project")
public class Project{
	@Id
	@GeneratedValue(generator="uuid")
	@GenericGenerator(name="uuid",strategy="uuid")
	private String id;
	@Column
	private String name;
	@Column
	private String description;
	@Column
	private String publishDate;
	@Column
	private String lastModifyDate;
	@Column
	private String content;
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="userid",nullable=false)
	private User user;
	@OneToOne(fetch=FetchType.EAGER,cascade=CascadeType.ALL)
	@JoinColumn(name="iconid",nullable=true)
	private MyIcon icon;
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getPublishDate() {
		return publishDate;
	}
	public void setPublishDate(String publishDate) {
		this.publishDate = publishDate;
	}
	public void setPublishDate(Date publishDate){
		this.publishDate = MyUtil.getDefaultDateFormat().format(publishDate);
	}
	public String getLastModifyDate() {
		return lastModifyDate;
	}
	public void setLastModifyDate(String lastModifyDate) {
		this.lastModifyDate = lastModifyDate;
	}
	public void setLastModifyDate(Date lastModifyDate) {
		this.lastModifyDate = MyUtil.getDefaultDateFormat().format(lastModifyDate);
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public MyIcon getIcon() {
		return icon;
	}
	public void setIcon(MyIcon icon) {
		this.icon = icon;
	}
	public Project(){}
	public Project(String name, String description, Date publishDate,
			Date lastModifyDate, User user, MyIcon icon) {
		super();
		this.name = name;
		this.description = description;
		this.publishDate = MyUtil.getDefaultDateFormat().format(publishDate);
		this.lastModifyDate = MyUtil.getDefaultDateFormat().format(lastModifyDate);
		this.content = "";
		this.user = user;
		this.icon = icon;
	}
}
